package org.jeecg.glr.iframe.controller;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.glr.entity.GlrVideo;
import org.jeecg.glr.iframe.service.IGlrIframeVideoMonitoringService;
import org.jeecg.glr.iframe.util.AjaxJson;
import org.jeecg.glr.service.IGlrVideoBdRecognizeService;
import org.jeecg.glr.service.IGlrVideoService;
import org.jeecg.glr.service.IGlrVideoYsService;
import org.jeecg.glr.util.HttpRequestUtil;
import org.jeecg.glr.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.jeecg.common.constant.CommonConstant.St_Access_Token;

/**
 *iframe使用
 * 视频播放功能
 */
@Slf4j
@Controller
@RequestMapping("/iframeGlr/faceDetectList")
public class GlrIframeFaceDetectList extends JeecgController<GlrVideo, IGlrVideoService> {

    @Autowired
    private IGlrIframeVideoMonitoringService glrIframeVideoMonitoringService;

    @Value("${glr.path.vue_url}")
    private String vue_url;

    /**
     * 人脸列表
     * @return
     */
    @RequestMapping("/index")
    public String list(Model model, HttpServletRequest request) throws Exception {
        try{
            LoginUser loginUser=glrIframeVideoMonitoringService.updateUserInfo(request);
            if (loginUser==null){
                return "redirect:"+vue_url;
            }
        }catch (Exception ex){
            return "redirect:"+vue_url;
        }
        model.addAttribute("AccessToken",request.getParameter(St_Access_Token));
        return "/glrTemplates/FaceDetectList/index";
    }

    @RequestMapping("/getFaceDetect")
    @ResponseBody
    public AjaxJson getFaceDetect(HttpServletRequest request,String fCount, String fId) throws Exception {
        LoginUser loginUser= glrIframeVideoMonitoringService.updateUserInfo(request);
        return glrIframeVideoMonitoringService.getFaceDetect(fCount,fId,loginUser);
    }

}
